package com.gzy.net_app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.gzy.net_app.R;
import com.gzy.net_app.bean.ImageInfo;
import java.util.ArrayList;
import java.util.List;

/**
 * @author : guzy
 * @program: net-app
 * @description: 人脸列表适配器
 * @date : 2022-03-26 18:56
 **/
public class NewFaceAdapter extends RecyclerView.Adapter<NewFaceListViewHolder> {
  List<ImageInfo.FacesBean> mFaceList = new ArrayList<>();
  Context context;
  private OnItemClickLitener mOnItemClickLitener;

  public NewFaceAdapter(Context context) {
    this.context = context;
  }

  public void updateFaceList(List<ImageInfo.FacesBean> faceList) {
    mFaceList = faceList;
    notifyDataSetChanged();
  }

  @NonNull @Override public NewFaceListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(context).inflate(R.layout.item_face, parent, false);
    return new NewFaceListViewHolder(view);
  }

  @Override public void onBindViewHolder(@NonNull NewFaceListViewHolder holder, int position) {
    holder.getTvAge().setText("大约：" + mFaceList.get(position).getFaceAge()+"岁");
    if (mFaceList.get(position).getGender().equals("male")) {
      holder.getTvSex().setText("男");
    } else {
      holder.getTvSex().setText("女");
    }
    if (mFaceList.get(position).getExpression().equals("nono")) {
      holder.getTvBiaoqing().setText("不笑");
    } else if (mFaceList.get(position).getExpression().equals("smile")) {
      holder.getTvBiaoqing().setText("微笑");
    } else if (mFaceList.get(position).getExpression().equals("laugh")) {
      holder.getTvBiaoqing().setText("大笑");
    } else {
      holder.getTvBiaoqing().setText("面无表情");
    }

    if (mFaceList.get(position).getFaceType().equals("square")) {
      holder.getTvLianXing().setText("方形脸");
    } else if (mFaceList.get(position).getExpression().equals("triangle")) {
      holder.getTvLianXing().setText("三角形脸");
    } else if (mFaceList.get(position).getExpression().equals("oval")) {
      holder.getTvLianXing().setText("椭圆行脸");
    } else if (mFaceList.get(position).getExpression().equals("heart")) {
      holder.getTvLianXing().setText("心形脸");
    } else if (mFaceList.get(position).getExpression().equals("round")) {
      holder.getTvLianXing().setText("圆脸");
    } else {
      holder.getTvLianXing().setText("无法判断");
    }
    holder.getTvAi().setText("颜值约为：" + mFaceList.get(position).getFaceBeauty());
  }

  @Override public int getItemCount() {
    return mFaceList.size();
  }

  public void setOnItemClickLitener(OnItemClickLitener mOnItemClickLitener) {
    this.mOnItemClickLitener = mOnItemClickLitener;
  }

  public interface OnItemClickLitener {
    void onItemClick(int position);
  }
}

class NewFaceListViewHolder extends RecyclerView.ViewHolder {
  TextView tvAge, tvSex, tvLianXing, tvBiaoqing, tvAi;

  public NewFaceListViewHolder(@NonNull View itemView) {
    super(itemView);
    tvAge = itemView.findViewById(R.id.tv_faceitme_age);
    tvSex = itemView.findViewById(R.id.tv_faceitme_sex);
    tvLianXing = itemView.findViewById(R.id.tv_faceitme_lianxing);
    tvBiaoqing = itemView.findViewById(R.id.tv_faceitme_biaoqing);
    tvAi = itemView.findViewById(R.id.tv_faceitme_AI);
  }

  public TextView getTvAge() {
    return tvAge;
  }

  public TextView getTvSex() {
    return tvSex;
  }

  public TextView getTvLianXing() {
    return tvLianXing;
  }

  public TextView getTvBiaoqing() {
    return tvBiaoqing;
  }

  public TextView getTvAi() {
    return tvAi;
  }
}